<?php
/**
 * Introduction: 用户表  member
 */

namespace Common\Model;


use Think\Model;

class MemberModel extends Model
{
    //定义数据库连接信息
    protected $connection;

    //定义表名
    protected $tableName = 'member';

    /**
     * 初始化
     */
    public function _initialize()
    {

        $this->connection = C('Databaese');

    }

    /**
     * 获取用户信息
     */
    public function getOne($memberId){
        $fields = ["userid", "name", "weixin", "mobile", "qq", "logo", "status","is_web","password"];
        $info = $this->where("userid=$memberId")->field($fields)->find();
        if (!empty($info)) {
            $info['memberId'] = $info['userid'];
        }
        return $info;
    }

    /**
     * 获取个人中心首页数据
     */
    public function index($member_id){
        $fields = ["m.userid", "m.name", "m.weixin", "m.mobile", "m.qq", "m.logo", "m.status","m.is_web","m.password",'t.account','t.level'];

        return $this->alias('m')->join("left join haiou_tarento as t on t.member_id=m.userid")->where("t.member_id=$member_id")->field($fields)->find();
    }

    /**
     * 获取一组用户的信息
     * @param array $memberId
     */
    public function getInfoByIds($membersId){
        $member_id = join(',',$membersId);
        $fields = ["userid", "name", "weixin", "mobile", "qq", "logo"];
        $list = $this->where("userid in ($member_id)")->field($fields)->select();
        if (!empty($list)) {
            foreach ($list as $k=>$item) {
                $list[$k]['memberId'] = $item['userid'];
            }
        }
        return $list;
    }
}